<?php 
require_once($_SERVER["DOCUMENT_ROOT"] . "/../sys/libs/init.lib"); 

$items = $db->getarray($queries->productsList());

?>

var items = new Array();
<?php 
	foreach ($items as $key => $item) {
		$id = $items[$key]->id;
		print "items[$id] = new Array(); \n";

		foreach ($item as $col => $val) {
			print "items[$id]['$col'] = '".str_replace("'", "", $val)."' \n"; 
		}
	}
?>

function buildValues(link,itemid) {
	var tr = '';
	for (tr = link; tr.nodeName !== 'TR'; tr = tr.parentNode);

	var rowid = tr.id;

	if (rowid && tr) {
		var descriptionfield = document.getElementById('item_description[New]['+rowid+']');
		descriptionfield.value = items[itemid]['DefaultDescription'];
		var quantityfield = document.getElementById('item_quantity[New]['+rowid+']');
		quantityfield.value = 1;
		var amountfield = document.getElementById('item_amounteach[New]['+rowid+']');
		amountfield.value = items[itemid]['Amount'];
		var taxamountfield = document.getElementById('item_taxamount[New]['+rowid+']');
		taxamountfield = items[itemid]['TaxAmount'];
	}
}

function submitDeleteForm(id) {
	if (id) {
		var frm = document.getElementById('delform');
		if (frm) {
			var input = document.getElementById('delform_id');
			if (input) {
				input.value = id;
				frm.submit();
			}
		}
	} 
}

function setValue(content,element) {
	var field = document.getElementById(element);
	if (field) {
		field.value = content;
	}
}


